|
1
|
|
|
var Slf4j = require('@ama-team/voxengine-sdk').Logger.Slf4j |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @typedef {object} Context~Options |
|
5
|
|
|
* |
|
6
|
|
|
* @property |
|
7
|
|
|
* @property {object} [arguments] |
|
8
|
|
|
* @property {object} [container] |
|
9
|
|
|
* @property {object} [state] |
|
10
|
|
|
* @property {LoggerOptions|IVarArgLogger} [logger] |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* This class is used as `this` for user-supplied and framework functions, |
|
15
|
|
|
* literally being execution context. |
|
16
|
|
|
* |
|
17
|
|
|
* @param {Run} run |
|
18
|
|
|
* @param {Context~Options} [options] |
|
19
|
|
|
* |
|
20
|
|
|
* @class |
|
21
|
|
|
* |
|
22
|
|
|
* @implements IExecutionContext |
|
23
|
|
|
* |
|
24
|
|
|
* @property {object} arguments |
|
25
|
|
|
* @property {object} state |
|
26
|
|
|
* @property {object} container |
|
27
|
|
|
*/ |
|
28
|
|
|
function Context (run, options) { |
|
29
|
|
|
options = options || {} |
|
30
|
|
|
|
|
31
|
|
|
var name = 'ama-team.vsf.execution.context' |
|
32
|
|
|
var logger = Slf4j.factory(options.logger, name) |
|
33
|
|
|
var self = this |
|
34
|
|
|
|
|
35
|
|
|
this.arguments = options.arguments || options.args || {} |
|
36
|
|
|
this.container = options.container || {} |
|
37
|
|
|
this.state = options.state || options.data || {} |
|
38
|
|
|
this.trigger = null |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @deprecated |
|
42
|
|
|
* @property {object} args |
|
43
|
|
|
*/ |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @deprecated |
|
47
|
|
|
* @property {object} data |
|
48
|
|
|
*/ |
|
49
|
|
|
Object.defineProperties(this, { |
|
50
|
|
|
data: { |
|
51
|
|
|
get: function () { |
|
52
|
|
|
return self.state |
|
53
|
|
|
} |
|
54
|
|
|
}, |
|
55
|
|
|
args: { |
|
56
|
|
|
get: function () { |
|
57
|
|
|
return self.arguments |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
}) |
|
61
|
|
|
|
|
62
|
|
|
Object.keys(logger).forEach(function (method) { |
|
63
|
|
|
if (typeof logger[method] !== 'function') { return } |
|
64
|
|
|
self[method] = function () { |
|
65
|
|
|
var target = self.logger || logger |
|
66
|
|
|
target[method].apply(target, arguments) |
|
67
|
|
|
} |
|
68
|
|
|
}) |
|
69
|
|
|
|
|
70
|
|
|
this.transitionTo = function (id, hints) { |
|
71
|
|
|
return run.transitionTo(id, hints) |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
module.exports = { |
|
76
|
|
|
Context: Context |
|
77
|
|
|
} |
|
78
|
|
|
|